/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      : 
 * Create Time : 2021-09-17
 * Version     : v0.1
 * Description : 
 *******************************************************************/

#ifndef _LS_BLE_OTA_FLASH_H_
#define _LS_BLE_OTA_FLASH_H_

/*----------------------------Head file----------------------------*/
#include "stdint.h"
#include "stdbool.h"
#include "user_config.h"

/*----------------------------macro file---------------------------*/
#define OTA_FLASH_BUF_MAX_SIZE  256

//Tag for phy62xx
#define OTA_FW_TAG  "OTAF"

#define OTAF_PARTITION_NUM_MAX  32

/*----------------------------type define--------------------------*/

//Struct for phy62xx
typedef struct {
    char tag[4];
    uint32_t partition_num;
    uint32_t nouse2[2];
    uint32_t part_info[4];
} BankBootInfoHeader_t;

/*typedef struct {
    uint32_t flashAddress;
    uint32_t runAddress;
    uint32_t partitionSize;
    uint32_t crc32Checksum;
} BootInfoPartition_t;*/

typedef struct {
    uint32_t write_idx;
	uint32_t write_size;
	uint8_t flash_buf[OTA_FLASH_BUF_MAX_SIZE];
} OtaFlashCtl_t;

/*----------------------------var define---------------------------*/							

/*-------------------------func declaration------------------------*/
extern void ota_flash_image_acitve(void);
extern bool ota_flash_check_header(uint32_t image_size);
extern void ota_flash_write_data(uint8_t *buf, uint32_t len);
extern void ota_flash_buf_conti_write_data(uint8_t *buf, uint32_t len, uint32_t bin_size);
extern bool ota_flash_calculate_checksum(uint32_t img_cs, uint32_t img_size);
extern void ota_flash_area_erase(uint32_t bin_size);

/*-----------------------------------------------------------------*/


#endif

